package com.restfinder.restaurant.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;

import lombok.Getter;
import lombok.Setter;

import com.restfinder.comment.model.Comment;
import com.restfinder.model.IEntity;
import com.restfinder.user.model.User;

@Entity
@Table(name="restaurants")
public class Restaurant implements IEntity {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue
	@Getter @Setter
	private long id;
	@Getter @Setter
	private String name;
	@Getter @Setter
	private String description;
	@Getter @Setter
	private String address;
	@Column(name="www_site")
	@Getter @Setter
	private String wwwSite;
	@Getter @Setter
	private double longitude;
	@Getter @Setter
	private double latitude;
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="owner_id")
	@ForeignKey(name="restaurants_fkey_owner_id")
	@Getter @Setter
	private User owner;
	@OneToMany(cascade=CascadeType.ALL, targetEntity=Comment.class, mappedBy="restaurant")
	@Getter @Setter
	private List<Comment> comments;
	
	
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if ((obj == null) || !(obj instanceof Restaurant)) {
			return false;
		}
		Restaurant restaurant = (Restaurant) obj;
		return restaurant.getId() == this.id;		
	}

	@Override
	public String toString() {
		return "Restaurant.id="+this.id;
	}
}
